package org.sirmupadbapi.persistencia;

import org.sirmupadbapi.beans.Cierremorosidadmensual;
import org.sirmupadbapi.beans.*;
import org.sirmupadbapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.sirmupadbapi.generales.Mensajeria;
import org.sirmupadbapi.generales.DataGManager;


/**
*
* @author
*/

public class CierremorosidadmensualPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
static DataGManager dataGManager;
static List<Cierremorosidadmensual> list;

public CierremorosidadmensualPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Cierremorosidadmensual cierremorosidadmensual ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into cierremorosidadmensual(anio,mes,id,tipoid,idregimen,morosidad,idmunicipio,numeromes)  values(?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setInt(1,cierremorosidadmensual.getAnio());
        pinsert.setString(2,cierremorosidadmensual.getMes());
        pinsert.setString(3,cierremorosidadmensual.getId());
        pinsert.setString(4,cierremorosidadmensual.getTipoid());
        pinsert.setString(5,cierremorosidadmensual.getIdregimen());
        pinsert.setDouble(6,cierremorosidadmensual.getMorosidad());
        pinsert.setString(7,cierremorosidadmensual.getIdmunicipio());
        pinsert.setInt(8,cierremorosidadmensual.getNumeromes());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Cierremorosidadmensual cierremorosidadmensual ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update cierremorosidadmensual set  anio=?, mes=?, id=?, tipoid=?, idregimen=?, morosidad=?, idmunicipio=?, numeromes=?  where  anio ='"+cierremorosidadmensual.getAnio()+"' and  mes ='"+cierremorosidadmensual.getMes()+"' and  id ='"+cierremorosidadmensual.getId()+"' and  tipoid ='"+cierremorosidadmensual.getTipoid()+"' and  idregimen ='"+cierremorosidadmensual.getIdregimen()+"' and  idmunicipio ='"+cierremorosidadmensual.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,cierremorosidadmensual.getAnio());
pupdate.setString(2,cierremorosidadmensual.getMes());
pupdate.setString(3,cierremorosidadmensual.getId());
pupdate.setString(4,cierremorosidadmensual.getTipoid());
pupdate.setString(5,cierremorosidadmensual.getIdregimen());
pupdate.setDouble(6,cierremorosidadmensual.getMorosidad());
pupdate.setString(7,cierremorosidadmensual.getIdmunicipio());
pupdate.setInt(8,cierremorosidadmensual.getNumeromes());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  cierremorosidadmensual set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Cierremorosidadmensual cierremorosidadmensual_old , Cierremorosidadmensual cierremorosidadmensual) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update cierremorosidadmensual set  anio=? ,  mes=? ,  id=? ,  tipoid=? ,  idregimen=? ,  idmunicipio=?  where  anio ='"+cierremorosidadmensual_old.getAnio()+"' and  mes ='"+cierremorosidadmensual_old.getMes()+"' and  id ='"+cierremorosidadmensual_old.getId()+"' and  tipoid ='"+cierremorosidadmensual_old.getTipoid()+"' and  idregimen ='"+cierremorosidadmensual_old.getIdregimen()+"' and  idmunicipio ='"+cierremorosidadmensual_old.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,cierremorosidadmensual.getAnio());pupdate.setString(2,cierremorosidadmensual.getMes());pupdate.setString(3,cierremorosidadmensual.getId());pupdate.setString(4,cierremorosidadmensual.getTipoid());pupdate.setString(5,cierremorosidadmensual.getIdregimen());pupdate.setString(7,cierremorosidadmensual.getIdmunicipio());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Cierremorosidadmensual cierremorosidadmensual ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from cierremorosidadmensual  where  anio = ? and  mes = ? and  id = ? and  tipoid = ? and  idregimen = ? and  idmunicipio = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setInt(1,cierremorosidadmensual.getAnio());
pdelete.setString(2,cierremorosidadmensual.getMes());
pdelete.setString(3,cierremorosidadmensual.getId());
pdelete.setString(4,cierremorosidadmensual.getTipoid());
pdelete.setString(5,cierremorosidadmensual.getIdregimen());
pdelete.setString(7,cierremorosidadmensual.getIdmunicipio());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from cierremorosidadmensual where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from cierremorosidadmensual  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Cierremorosidadmensual cierremorosidadmensual) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from cierremorosidadmensual where anio='"+cierremorosidadmensual.getAnio()+"' and mes='"+cierremorosidadmensual.getMes()+"' and id='"+cierremorosidadmensual.getId()+"' and tipoid='"+cierremorosidadmensual.getTipoid()+"' and idregimen='"+cierremorosidadmensual.getIdregimen()+"' and idmunicipio='"+cierremorosidadmensual.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Cierremorosidadmensual findByPrimaryKey(Cierremorosidadmensual cierremorosidadmensual) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from cierremorosidadmensual where anio='"+cierremorosidadmensual.getAnio()+"' and mes='"+cierremorosidadmensual.getMes()+"' and id='"+cierremorosidadmensual.getId()+"' and tipoid='"+cierremorosidadmensual.getTipoid()+"' and idregimen='"+cierremorosidadmensual.getIdregimen()+"' and idmunicipio='"+cierremorosidadmensual.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            cierremorosidadmensual.setAnio(rs.getInt("anio"));
cierremorosidadmensual.setMes(rs.getString("mes"));
cierremorosidadmensual.setId(rs.getString("id"));
cierremorosidadmensual.setTipoid(rs.getString("tipoid"));
cierremorosidadmensual.setIdregimen(rs.getString("idregimen"));
cierremorosidadmensual.setMorosidad(rs.getDouble("morosidad"));
cierremorosidadmensual.setIdmunicipio(rs.getString("idmunicipio"));
cierremorosidadmensual.setNumeromes(rs.getInt("numeromes"));
    }
    rs.close();
    psquery.close();
 return cierremorosidadmensual;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByAnio()
*/

public static List<Cierremorosidadmensual> findByAnio(Cierremorosidadmensual cierremorosidadmensual,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Cierremorosidadmensual>();
      String sql = "select * from cierremorosidadmensual where anio='"+cierremorosidadmensual.getAnio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByMes()
*/

public static List<Cierremorosidadmensual> findByMes(Cierremorosidadmensual cierremorosidadmensual,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Cierremorosidadmensual>();
      String sql = "select * from cierremorosidadmensual where mes='"+cierremorosidadmensual.getMes()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findById()
*/

public static List<Cierremorosidadmensual> findById(Cierremorosidadmensual cierremorosidadmensual,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Cierremorosidadmensual>();
      String sql = "select * from cierremorosidadmensual where id='"+cierremorosidadmensual.getId()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTipoid()
*/

public static List<Cierremorosidadmensual> findByTipoid(Cierremorosidadmensual cierremorosidadmensual,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Cierremorosidadmensual>();
      String sql = "select * from cierremorosidadmensual where tipoid='"+cierremorosidadmensual.getTipoid()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdregimen()
*/

public static List<Cierremorosidadmensual> findByIdregimen(Cierremorosidadmensual cierremorosidadmensual,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Cierremorosidadmensual>();
      String sql = "select * from cierremorosidadmensual where idregimen='"+cierremorosidadmensual.getIdregimen()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByMorosidad()
*/

public static List<Cierremorosidadmensual> findByMorosidad(Cierremorosidadmensual cierremorosidadmensual,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Cierremorosidadmensual>();
      String sql = "select * from cierremorosidadmensual where morosidad='"+cierremorosidadmensual.getMorosidad()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdmunicipio()
*/

public static List<Cierremorosidadmensual> findByIdmunicipio(Cierremorosidadmensual cierremorosidadmensual,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Cierremorosidadmensual>();
      String sql = "select * from cierremorosidadmensual where idmunicipio='"+cierremorosidadmensual.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByNumeromes()
*/

public static List<Cierremorosidadmensual> findByNumeromes(Cierremorosidadmensual cierremorosidadmensual,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Cierremorosidadmensual>();
      String sql = "select * from cierremorosidadmensual where numeromes='"+cierremorosidadmensual.getNumeromes()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Cierremorosidadmensual> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Cierremorosidadmensual>();
  String sql = "select * from cierremorosidadmensual";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from cierremorosidadmensual";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from cierremorosidadmensual where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from cierremorosidadmensual";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from cierremorosidadmensual where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Cierremorosidadmensual> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Cierremorosidadmensual>();
  String sql = "select * from cierremorosidadmensual where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Cierremorosidadmensual> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Cierremorosidadmensual>();
  String sql = "select * from cierremorosidadmensual";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "cierremorosidadmensual" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Cierremorosidadmensual cierremorosidadmensual2 = new Cierremorosidadmensual(
         rs.getInt("anio"),rs.getString("mes"),rs.getString("id"),rs.getString("tipoid"),rs.getString("idregimen"),rs.getDouble("morosidad"),rs.getString("idmunicipio"),rs.getInt("numeromes"));
            
            
       list.add(cierremorosidadmensual2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
